package com.imti.mapper;

import com.imti.model.Exam;
import org.apache.ibatis.annotations.*;

import java.util.List;

public interface ExamManageMapper {

    @Select("select * from t_exam")
    @Results(id = "examAllMapper",value = {
            @Result(column = "paper_id",property = "paperId"),
            @Result(column = "start_time",property = "startTime"),
            @Result(column = "end_time",property = "endTime"),
            @Result(column = "user_id",property = "userId"),
            @Result(column = "create_time",property = "createTime")
    })
    List<Exam> findAllExam();

    @Insert("insert into t_exam (paper_id,title,intro,start_time,end_time,state,user_id,create_time)" +
            "values(#{paperId},#{title},#{intro},#{startTime},#{endTime},#{state},#{userId},CURRENT_TIMESTAMP())")
    int addExamById(Exam exam);

    @ResultMap("examAllMapper")
    @Select("select * from t_exam where id = #{id}")
    Exam updateExamsById(Integer id);

    @Update("update t_exam set title = #{title},intro = #{intro},start_time = #{startTime},end_time = #{endTime},state = #{state} where id = #{id}")
    int update(Exam exam);
}
